<?php

include_once("./resource/SDK/CCPRestSmsSDK.php");
class Involved_MobileModel extends BaseModel
{
    /**
     * 发送短信验证
     * @param $to
     * @param $datas
     * @param $tempId
     * @return int
     */
    function sendTemplateSMS($to,$datas,$tempId)
    {

        // 初始化REST SDK
        global $accountSid,$accountToken,$appId,$serverIP,$serverPort,$softVersion;

        $accountSid= '8a48b551544cd73f0154893f6f383aaf';
        $accountToken= 'c8a7e905a48c4ceab3613ef27bae589d';
        $appId='8a216da855bed8870155bf25e7a200a3';
        $serverIP='app.cloopen.com';
        $serverPort='8883';
        $softVersion='2013-12-26';

        $rest = new REST($serverIP,$serverPort,$softVersion);
        $rest->setAccount($accountSid,$accountToken);
        $rest->setAppId($appId);
        // 发送模板短信
        //echo "Sending TemplateSMS to $to <br/>";
        $result = $rest->sendTemplateSMS($to,$datas,$tempId);
        if($result == NULL ) {
            echo "result error!";
            die;
        }
        if($result->statusCode!=0) {
//            echo "error code :" . $result->statusCode . "<br>";
//            echo "error msg :" . $result->statusMsg . "<br>";
            return $result->statusCode;
            //TODO 添加错误处理逻辑
        }else{
//            echo "Sendind TemplateSMS success!<br/>";
//            // 获取返回信息
//            $smsmessage = $result->TemplateSMS;
//            echo "dateCreated:".$smsmessage->dateCreated."<br/>";
//            echo "smsMessageSid:".$smsmessage->smsMessageSid."<br/>";
//            //TODO 添加成功处理逻辑
            return 10000;
        }
    }

}
